package com.peng.util;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;

import java.text.SimpleDateFormat;

public class JsonUtil {

    public static String JsonString(Object obj) throws JsonProcessingException {
        return JsonString(obj,"yyyy-MM-dd HH:mm:ss");
    }

    public static String JsonString(Object object,String str) throws JsonProcessingException {
        ObjectMapper om=new ObjectMapper();
        om.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS,false);
        SimpleDateFormat sip=new SimpleDateFormat(str);
        om.setDateFormat(sip);
        return om.writeValueAsString(object);
    }
}
